import pymysql

conn = pymysql.Connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='123456',
    database='mydb',
    charset='utf8',
)

cursor = conn.cursor()
#开启事务
conn.begin()
  # sql语句
sql1 = "update account set balance=balance-200222222 "
sql2 = "update account set balance=balance+200 "
try:
	#执行sql语句
    cursor.execute(sql2)
    conn.commit()
    print("转账成功！")
except:
	#事务回滚
    conn.rollback()
    print("由于ATM机故障，转账失败~~~")

finally:
    cursor.close()
    conn.close()
